# -*- coding: utf-8 -*-

"""
@File    : 02_栅格NC文件展示.py
@Author  : fungis@163.com
@notice  :
"""
import matplotlib.pylab as plt  # 画图模块
import netCDF4 as nc

'''
安装netCDF4库
conda install netCDF4 -c https://mirrors.aliyun.com/anaconda/pkgs/main/ -y
'''
data = './data-use/nc/RGB.nc'  # 文件存放路径

raster = nc.Dataset(data)  # 读取raster文件

lons = raster.variables['x'][:]  # 经度值
lats = raster.variables['y'][:]  # 纬度值
ele = raster.variables['Band1'][:]  # 波段值

plt.title('gdal-netCDF4')  # 创建名为gdal-netCDF4的标题
plt.imshow(ele, cmap='rainbow')  # 绘图，配色为rainbow
plt.colorbar()  # 绘制图例
plt.savefig("./results/20220917.01.png", dpi=300)
plt.show()
raster.close()  # 关闭raster文件
